home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World's Largest Collection of Windows Software
/
The World's Largest Collection of Windows Software - Disc 1.iso
/
connect
/
_b1
/
mrun211
/
mrun211g.was
< prev
next >
Wrap
Text File
|
1993-05-01
|
45KB
|
1,685 lines
;MailRun v2.11: Part G, domailrun
;1992-1993 Gerald P. Sully, all rights reserved.
#COMMENT
**************************************************************************
**************************************************************************
*
* The following procedures form the engine of the script. First
* makedir() is called to create a dialing directory for BBSs listed
* in the *.MRN file that have pending items. Each BBS is called,
* and on connection, each pending item listed for that BBS is executed
* by dobbs(). These tasks are performed by sendmail(), getmail(),
* ulfile(), dlfile(), and sendcommand(). As each task is completed,
* the task list window is updated.
*
* While online, the key procedure is holding() which keeps track of the
* length of time the board has been inactive, checks for dropped carrier
* and obtains the current line from the terminal screen so that it can
* be parsed by the various procedures that respond to prompts. The
* latter include checkbaseset(), checkcommandprompt(), checkmailprompt()
* and the like.
*
**************************************************************************
**************************************************************************
#ENDCOMMENT
#define MRUN211G
#define MRUN211AG
#define GOTOFILE 1
#define GOTOMAIN 0
string MainBoxTabs, prompt
integer xferstatus, holdstatus, foundstatus
#include "MRUN211.h"
#comment
*********************************************************************
*
* MAIN()
*
* Calls menudim(), checkchild(), maketasklist(), dobbs()
* mailrunbox(), parsedialog(), makequeue(), readbbs(),
* makefullname(), findstring(), capturescreen()
*
* Main first calls the initialization routines, then puts
* up the main dialog box and dispatches each requested
* action.
*
*********************************************************************
#endcomment
proc main
string DialString, PhoneNum, ComString, ComMsg, BBSName
string CnctFail1, CnctFail2, CnctFail3, CnctFail4, CnctFail5
string char
integer ComStringLength
integer Attempts, MaxAttempts, DialOutTime, RingInterrupt
integer i, j, n
integer FirstCall
menudim()
checkchild()
profilerd MailRunIni "MailRun" "MailRunDir" MailRunDir
TaskList = makefullname(TempDir, "TASKLIST.TMP")
findfirst MailRun
MailRunTrunc = $FILENAME
maketasklist()
mailrunbox()
makequeue()
;interface is turned on by makequeue
when dialog call parsedialog
profilerd MailRun "MailRun" "LogRun" LogRun
if LogRun
profilerd MailRun "MailRun" "AnsiInLog" AnsiInLog
if AnsiInLog
set capture mode append RAW
else
set capture mode append VISUAL
endif
capture ON
endif
profilerd MailRun "MailRun" "DialAttempts" MaxAttempts
fetch modem nocnct1 CnctFail1
fetch modem nocnct2 CnctFail2
fetch modem nocnct3 CnctFail3
fetch modem nocnct4 CnctFail4
fetch modem nocnct5 CnctFail5
Attempts = 1
FirstCall = 1
while Attempts <= MaxAttempts
itoa Attempts AttemptNum
updatedlg 64
;Keep dialing until the maximum number of attempts has been made
;reread MaxAttempts on each loop in case the user changes settings
profilerd MailRun "MailRun" "DialAttempts" MaxAttempts
n = 1
DialString = getdialstring(&n)
if n == 0
exitwhile
endif
while not NULLSTR DialString
;Loop until all numbers have been called
set aspect rxdata ON
rxflush
if FirstCall != 1
;Don't pause if this is the first call in the loop
profilerd MailRun "MailRun" "DialPause" j
profilerd MailRun "MailRun" "RingInterrupt" RingInterrupt
while j > 0
statmsg "Last Message: %s Pausing %d" ComMsg j
pause 1
j--
ComStringLength = $RXCOUNT
comgets ComString ComStringLength
if RingInterrupt && findstring(ComString, "RING")
capturescreen()
capturestr \
"`r`n`r`n**** Interrupted by Incoming Call ****`r`n`r`n"
statmsg "Mailrun interrupted by incoming call"
capture OFF
exit
endif
endwhile
else
FirstCall = 0
endif
;Dial the BBS
strextract PhoneNum DialString "`t" 0
strextract char DialString "`t" 1
atoi char i
BBS = readbbs(i)
profilerd MailRun BBS "BBSName" BBSName
strfmt ComString "ATDT%s`r" PhoneNum
strlen ComString ComStringLength
computs ComString ComStringLength
;rxdata must be on in order to get characters from the modem
ComString = ""
ComMsg = ""
profilerd MailRun "MailRun" "DialTimeOut" DialOutTime
while (!$CARRIER) && (DialOutTime > 0)
;Loop until a connection is made, timeout is reached, or a
;negative connect message is received
ComStringLength = $RXCOUNT
comgets ComString ComStringLength
if strfind ComString CnctFail1
ComMsg = CnctFail1
exitwhile
elseif strfind ComString CnctFail2
ComMsg = CnctFail2
exitwhile
elseif strfind ComString CnctFail3
ComMsg = CnctFail3
exitwhile
elseif strfind ComString CnctFail4
ComMsg = CnctFail4
exitwhile
elseif strfind ComString CnctFail5
ComMsg = CnctFail5
exitwhile
endif
rxflush
statmsg "Dialing %s %s Waiting %d" \
PhoneNum BBSName DialOutTime
pause 1
DialOutTime--
endwhile
set aspect rxdata OFF
if DialOutTime == 0
;If dial timed out...
hangup
ComMsg = "TIMEOUT"
endif
if $CARRIER
;if connected to a BBS...
statmsg "Connected to %s" BBSName
dobbs()
makequeue()
statmsg ""
FirstCall = 1
n--
endif
n++
DialString = getdialstring(&n)
endwhile
Attempts++
endwhile
capture OFF
statmsg ""
endproc
#comment
*********************************************************************
*
* DOBBS()
*
* Called by main()
*
* Calls readitem(), writeitem(), sendscript(), logoff(), fileexit()
* maketasklist(), gettaskstring(), getcommandprompt(),
* getmail(), sendmail(), dlfile(), ulfile(), sendcommand(),
*
* Dispatches pending tasks for the BBS to which MailRun
* is connected.
*
*********************************************************************
#endcomment
proc dobbs
string Pending, TaskType, BBSName, BBSType
integer FailCode, j
;Return to this point with a FailCode of 1 if carrier
;is lost or the BBS times out
Failcode = 0
setjmp ErrorFail FailCode
if FailCode == 0
profilerd MailRun BBS "BBSType" BBSType
profilerd MailRun BBS "BBSName" BBSName
profilerd MailRun "MailRun" "IdleTimeout" IdleTimeout
;Assume login to Conference 0
CurrentConf = "0"
Conf = "0"
;Highlight the current BBS in the task list
TaskItem = gettaskstring(BBS, 0)
updatedlg 16
;The first item must be read before the first holding()
;(which occurs in getcommandprompt()) in case an error occurs.
j = 1
Item = readitem(BBS, j)
getcommandprompt()
while not NULLSTR Item
;Loop through each Item for this BBS
TaskItem = gettaskstring(BBS, j)
updatedlg 16
strextract Pending Item "," 0
if strcmpi Pending "1"
;If the item is pending, execute it
strextract TaskType Item "," 2
switch TaskType
case "GetMail"
statmsg "Getting Mail Packet"
getmail()
endcase
case "SendMail"
statmsg "Sending Reply Packet"
sendmail()
endcase
case "GetFile"
statmsg "Downloading File"
dlfile()
endcase
case "SendFile"
statmsg "Uploading File"
ulfile()
endcase
case "SendCommand"
statmsg "Sending Command"
sendcommand()
endcase
case "SendScript"
statmsg "Executing Script"
sendscript()
endcase
endswitch
;Update the task list
TaskItem = gettaskstring(BBS, j)
writeitem(BBS, j, Item)
taskfilefwd(TaskItem)
TaskItem = gettaskstring(BBS, j)
fputs TaskFile TaskItem
taskfileend()
ItemR--
updatecount()
updatedlg 80
endif
j++
Item = readitem(BBS, j)
endwhile
getcommandprompt()
else
;If timeout or loss of carrier
;Change unfinished items to errors
while not NULLSTR Item
strextract Pending Item "," 0
if strcmpi Pending "1"
strupdt Item "2" 0 1
writeitem(BBS, j, Item)
endif
j++
Item = readitem(BBS, j)
endwhile
maketasklist()
j--
Item = readitem(BBS, j)
TaskItem = gettaskstring(BBS, j)
updatedlg 80
endif
statmsg "Logging off"
logoff()
if $CARRIER
;If still connected after logoff...
errormsg "Unable to drop carrier; aborting..."
;abort the mailrun
fileexit()
endif
endproc
#comment
*********************************************************************
*
* MAKEQUEUE()
*
* Called by main(), parsedialog()
*
* Calls openfile(), readbbs(), checkpending(),
* interfaceon(), interfaceoff(), makefullname()
*
* Creates a file of phone numbers for BBSs that have
* pending items in the current mailrun.
*
*********************************************************************
#endcomment
proc makequeue
string PhoneNum, Number_X, QueueList, BBSid
integer i, j
interfaceoff()
QueueList = makefullname(TempDir, "QUEUE.TMP")
openfile(QueueListFile, QueueList, _CREATE, _NORMAL)
i = 1
BBSid = readbbs(i)
;Loop through each BBS
while not NULLSTR BBSid
if checkpending(BBSid)
;If the BBS has pending items...
j = 1
strfmt Number_X "Number_%d" j
profilerd MailRun BBSid Number_X PhoneNum
;Loop through each phone number
while not NULLSTR PhoneNum
fstrfmt QueueListFile "%s`t%d`r`n" PhoneNum i
j++
strfmt Number_X "Number_%d" j
profilerd MailRun BBSid Number_X PhoneNum
endwhile
endif
i++
BBSid = readbbs(i)
endwhile
fclose QueueListFile
interfaceon()
endproc
#comment
*********************************************************************
*
* GETDIALSTRING()
*
* Called by main()
*
* Calls makefullname(), interfaceon(), interfaceoff(),
* openfile()
*
* Gets a DialString from the queue. The string contains
* a phone number and a bbs coordinate.
*
*********************************************************************
#endcomment
func getdialstring : string
intparm n
integer i
string DialString, QueueList
interfaceoff()
DialString = ""
QueueList = makefullname(TempDir, "QUEUE.TMP")
openfile(QueueListFile, QueueList, _READWRITE, _TEXT)
i = 1
while i <= n
fgets QueueListFile DialString
if NULLSTR DialString
n = 0
exitwhile
endif
i++
endwhile
fclose QueueListFile
interfaceon()
return DialString
endfunc
#comment
*********************************************************************
*
* GETCOMMANDPROMPT()
*
* Called by dobbs(), getconfprompt(), getotherprompt(),
* ulfile(), dlfile(), sendcommand(), sendscript()
*
* Calls holding(), checkcommandprompt()
*
* Responds to prompts until the "Command" prompt is received.
*
*********************************************************************
#endcomment
proc getcommandprompt
when quiet 1 call checkcommandprompt
holding()
clearwhen quiet
endproc
#comment
*********************************************************************
*
* CHECKCOMMANDPROMPT()
*
* Called by getcommandprompt()
*
* Calls checkbaseset(), findstring(), endhold()
*
* Checks the prompt and sends the appropriate response.
*
*********************************************************************
#endcomment
proc checkcommandprompt
string NamePrompt, UserName, BBSType
string PWordPrompt, PWord, FilePrompt
string MailPrompt, CommandPrompt, MsgMenuPrompt
profilerd MailRun BBS "BBSType" BBSType
profilerd MailRun BBS "NamePrompt" NamePrompt
profilerd MailRun BBS "PWordPrompt" PWordPrompt
profilerd MailRun BBS "FilePrompt" FilePrompt
profilerd MailRun BBS "MailPrompt" MailPrompt
profilerd MailRun BBS "CommandPrompt" CommandPrompt
profilerd MailRun BBS "MsgMenuPrompt" MsgMenuPrompt
if !(checkbaseset())
if findstring(prompt, MailPrompt) || \
(findstring(BBSType, "WildCat") && \
findstring(prompt, MsgMenuPrompt))
transmit "q^M"
elseif findstring(BBSType, "WildCat") && \
findstring(prompt, "Join conference")
transmit Conf
transmit "^M"
elseif findstring(prompt, NamePrompt)
profilerd MailRun BBS "UserName" UserName
transmit UserName
transmit "^M"
elseif findstring(prompt, PWordPrompt)
profilerd MailRun BBS "PWord" PWord
transmit PWord
transmit "^M"
elseif findstring(prompt, "Escape") || findstring(prompt, " ESC ")
;send escape character
computc 0x1B
if findstring(prompt, "twice") || findstring(prompt, "two")
;pause 50 milliseconds
mspause 50
computc 0x1B
endif
elseif findstring(prompt, CommandPrompt) || \
findstring(prompt, FilePrompt)
endhold()
endif
endif
endproc
#comment
*********************************************************************
*
* GETCONFPROMPT()
*
* Called by ulfile(), dlfile()
*
* Calls getcommandprompt(), findstring()
*
* Changes conferences if necessary.
*
*********************************************************************
#endcomment
proc getconfprompt
string BBSType
profilerd MailRun BBS "BBSType" BBSType
if not strcmpi CurrentConf Conf
;If we have to change conferences...
if findstring(BBSType, "WildCat")
transmit "j^M"
elseif findstring(BBSType, "PCBoard")
transmit "j;"
transmit Conf
transmit "^M"
endif
getcommandprompt()
CurrentConf = Conf
endif
endproc
#comment
*********************************************************************
*
* CHECKMAILPROMPT()
*
* Called by getmail(), sendmail()
*
* Calls endhold(), findstring(), checkbaseset()
*
* Opens the mail door and gets the mail prompt.
*
*********************************************************************
#endcomment
proc checkmailprompt
string MailPrompt, CommandPrompt, MailDoor, FilePrompt
string BBSType, MsgMenuPrompt
profilerd MailRun BBS "BBSType" BBSType
profilerd MailRun BBS "MsgMenuPrompt" MsgMenuPrompt
profilerd MailRun BBS "MailPrompt" MailPrompt
profilerd MailRun BBS "CommandPrompt" CommandPrompt
profilerd MailRun BBS "FilePrompt" FilePrompt
if !(checkbaseset())
if findstring(BBSType, "WildCat") && \
(findstring(prompt, CommandPrompt) || findstring(prompt, FilePrompt))
transmit "M^M"
elseif findstring(prompt, MailPrompt)
endhold()
elseif (findstring(prompt, CommandPrompt) && \
(findstring(BBSType, "PCBoard") || findstring(BBSType, "RBBS"))) || \
(findstring(BBSType, "WildCat") && findstring(prompt, MsgMenuPrompt))
profilerd MailRun BBS "MailDoor" MailDoor
transmit MailDoor
transmit "^M"
endif
endif
endproc
#comment
*********************************************************************
*
* CHECKDESCPROMPT()
*
* Called by ulfile(), dlfile()
*
* Calls findstring(), endhold(), checkbaseset()
*
* Checks for presense of the upload description prompt.
* Sets promptstatus to 0 if the file already on the board.
*
*********************************************************************
#endcomment
proc checkdescprompt
string ULDescPrompt, DLUnavPrompt, CommandPrompt, FilePrompt, BBSType
profilerd MailRun BBS "BBSType" BBSType
profilerd MailRun BBS "ULDescPrompt" ULDescPrompt
profilerd MailRun BBS "DLUnavPrompt" DLUnavPrompt
profilerd MailRun BBS "CommandPrompt" CommandPrompt
profilerd MailRun BBS "FilePrompt" FilePrompt
if !(checkbaseset())
if findstring(prompt, "file # 2") || findstring(prompt, "file #2") || \
findstring(prompt, "Keywords? [")
transmit "^M"
elseif (findstring(BBSType, "WildCat") && \
(findstring(prompt, "password protect") || \
findstring(prompt, "detailed") || \
findstring(prompt, "last download"))) || \
(findstring(BBSType, "RBBS") && \
findstring(prompt, "Extended description"))
transmit "n^M"
elseif findstring(prompt, "after upload")
transmit "c^M"
elseif findstring(BBSType, "RBBS") && findstring(prompt, "To A)ll")
transmit "a^M"
foundstatus = 1
endhold()
elseif findstring(prompt, ULDescPrompt)
foundstatus = 1
endhold()
elseif findstring(prompt, DLUnavPrompt) || \
findstring(prompt, "file # 1") || findstring(prompt, "file #1") || \
findstring(prompt, CommandPrompt) || findstring(prompt, FilePrompt)
if findstring(BBSType, "Auntie") && !(findstring(prompt, FilePrompt))
transmit "q^M"
endif
foundstatus = 0
endhold()
endif
endif
endproc
#comment
*********************************************************************
*
* GOTULDLPROMPT()
*
* Called by ulfile()
*
* Releases the hold when the upload prompt is received.
*
*********************************************************************
#endcomment
proc gotuldlprompt
foundstatus = 1
endhold()
endproc
#comment
*********************************************************************
*
* GETOTHERPROMPT()
*
* Called by sendmail(), getmail(), ulfile(), dlfile(),
* sendcommand(), sendscript()
*
* Calls findstring(), getcommandprompt()
*
* For BBSs with a separate File prompt, moves to or from
* the prompt.
*
*********************************************************************
#endcomment
proc getotherprompt
intparm gotoplace
string FilePrompt, BBSType
profilerd MailRun BBS "BBSType" BBSType
profilerd MailRun BBS "FilePrompt" FilePrompt
if !(findstring(prompt, FilePrompt)) && (gotoplace == GOTOFILE)
transmit "f^M"
elseif findstring(prompt, FilePrompt) && (gotoplace == GOTOMAIN)
transmit "q"
if findstring(BBSType, "RBBS")
transmit ";m"
endif
transmit "^M"
endif
getcommandprompt()
endproc
#comment
*********************************************************************
*
* CHECKBASESET()
*
* Called by checkcommandprompt(), checkmailprompt(),
* checkdescprompt()
*
* Calls findstring()
*
* Checks the base set of prompts. Returns 1 if a prompt
* was found; otherwise returns 0.
*
*********************************************************************
#endcomment
func checkbaseset : integer
string LangPrompt, LangNumber, GraphicsPrompt, ScanPrompt
string MorePrompt, ViewPrompt, CallingFrom, UserResp1, UserResp2
string ContinuePrompt, UserPrompt1, UserPrompt2, BBSType
profilerd MailRun BBS "BBSType" BBSType
profilerd MailRun BBS "CallingFrom" CallingFrom
profilerd MailRun BBS "UserPrompt1" UserPrompt1
profilerd MailRun BBS "UserPrompt2" UserPrompt2
profilerd MailRun BBS "UserResp1" UserResp1
profilerd MailRun BBS "UserResp2" UserResp2
profilerd MailRun BBS "ContinuePrompt" ContinuePrompt
profilerd MailRun BBS "ScanPrompt" ScanPrompt
profilerd MailRun BBS "MorePrompt" MorePrompt
profilerd MailRun BBS "ViewPrompt" ViewPrompt
profilerd MailRun BBS "LangPrompt" LangPrompt
profilerd MailRun BBS "GraphicsPrompt" GraphicsPrompt
if findstring(prompt, UserPrompt1)
transmit UserResp1
transmit "^M"
elseif findstring(prompt, UserPrompt2)
transmit UserResp2
transmit "^M"
elseif findstring(prompt, ScanPrompt) || \
(findstring(prompt, MorePrompt) && !(findstring(BBSType, "WildCat")))
transmit "n^M"
elseif findstring(prompt, MorePrompt) && \
findstring(BBSType, "WildCat")
transmit "s^M"
elseif (findstring(prompt, ContinuePrompt) && \
findstring(BBSType, "PCBoard")) || \
findstring(prompt, CallingFrom)
transmit "y^M"
elseif findstring(prompt, ContinuePrompt) && \
!(findstring(BBSType, "PCBoard"))
transmit "^M"
elseif findstring(prompt, ViewPrompt)
if findstring(BBSType, "PCBoard") || findstring(BBSType, "WildCat")
transmit "n"
elseif findstring(BBSType, "RBBS")
transmit "q"
endif
transmit "^M"
elseif findstring(prompt, LangPrompt)
profilerd MailRun BBS "LangNumber" LangNumber
transmit LangNumber
transmit "^M"
elseif findstring(prompt, GraphicsPrompt)
profilerd MailRun BBS "GraphicsOn" GraphicsOn
if GraphicsOn == 0
transmit "n^M"
else
transmit "y^M"
endif
else
return 0
endif
return 1
endfunc
#comment
*********************************************************************
*
* HOLDING()
*
* Called by getcommandprompt(), sendmail(), getmail(),
* ulfile(), dlfile(), sendcommand()
*
* Calls capturescreen()
*
* Jumps to ErrorFail in dobbs()
*
* Stalls script while waiting for the result of a when
* command. Sends script to next BBS if there is a
* timeout, or if carrier is lost.
*
*********************************************************************
#endcomment
proc holding
string LastPrompt
IdleTimer = 1
holdstatus = 1
prompt = ""
xferstatus = $FILEXFER
while (IdleTimer < IdleTimeout) && (holdstatus == 1) && \
(xferstatus == 0) && $CARRIER
pause 1
termgets $ROW 0 prompt 79
if not strcmp prompt LastPrompt
;if anything has been received, reset the timer
IdleTimer = 1
endif
LastPrompt = prompt
if !(IdleTimer % 15)
;Send a carriage return every 15 seconds
transmit "^M"
endif
IdleTimer++
xferstatus = $FILEXFER
endwhile
if (IdleTimer == IdleTimeout) || ($CARRIER == 0)
;If there has been a timeout, lost carrier or user escape...
clearwhen quiet
;set FailCode and get out
capturescreen()
if IdleTimer == IdleTimeout
capturestr "`r`n`r`n*** Timed out waiting for prompt ***`r`n`r`n"
else
capturestr "`r`n`r`n*********** Lost carrier ***********`r`n`r`n"
endif
longjmp ErrorFail 1
endif
endproc
#comment
*********************************************************************
*
* ENDHOLD()
*
* Releases a hold placed by holding()
*
*********************************************************************
#endcomment
proc endhold
holdstatus = 0
endproc
#comment
*********************************************************************
*
* WAITXFER()
*
* Called by sendmail(), getmail(), ulfile(), dlfile()
*
* Stalls script until a file transfer has been completed.
*
*********************************************************************
#endcomment
proc waitxfer
xferstatus = $FILEXFER
while xferstatus == 1
xferstatus = $FILEXFER
endwhile
endproc
#comment
*********************************************************************
*
* SENDMAIL()
*
* Called by dobbs()
*
* Calls checkmailprompt(), holding(), waitxfer(),
* findstring(), makefullname(), getotherprompt(),
* capturescreen()
*
* Uploads a *.REP packet for the current BBS.
*
*********************************************************************
#endcomment
proc sendmail
string MailULPrompt, MailXferProt, BBSType
string ReplyFile, ReplyDir
string Pending, temp
integer j
profilerd MailRun BBS "BBSType" BBSType
profilerd MailRun "MailRun" "ReplyDir" ReplyDir
ReplyFile = makefullname(ReplyDir, BBS)
strcat ReplyFile ".REP"
if isfile ReplyFile
;If there is a REP packet waiting...
if findstring(BBSType, "Auntie") || findstring(BBSType, "RBBS")
getotherprompt(GOTOMAIN)
endif
if findstring(BBSType, "Auntie")
transmit "QMU^M"
else
when quiet 1 call checkmailprompt
holding()
clearwhen quiet
transmit "u^M"
endif
profilerd MailRun BBS "MailULPrompt" MailULPrompt
when target 0 MailULPrompt call endhold
holding()
clearwhen target 0
set upldpath ReplyDir
profilerd MailRun BBS "MailXferProt" MailXferProt
sendfile MailXferProt ReplyFile
;Hold until the transfer starts
holding()
;Hold until the transfer finishes
waitxfer()
if xferstatus == 2
;If upload was successful...
;Rename the .REP packet as *.OLD
temp = ReplyFile
strlen temp j
j -= 3
strupdt temp "OLD" j 3
delfile temp
rename ReplyFile temp
;Mark the Item as completed
Pending = "0"
ItemC++
else
;Otherwise, mark it as an error
Pending = "2"
ItemE++
capturescreen()
capturestr "`r`n`r`n******* Error in File Transfer *******`r`n`r`n"
endif
else
Pending = "0"
ItemC++
endif
;Update the *.MRN file
strupdt Item Pending 0 1
endproc
#comment
*********************************************************************
*
* GETMAIL()
*
* Called by dobbs()
*
* Calls checkmailprompt(), holding(), waitxfer, cleardir(),
* renameqwk(), checkmail(), findstring(), makefullname(),
* getotherprompt(), capturescreen()
*
* Downloads a *.QWK packet for the current BBS.
*
*********************************************************************
#endcomment
proc getmail
string MailFile, MailDLDir, MailDLPrompt, MailXferProt, CommandPrompt
string Pending, temp, BBSType
profilerd MailRun BBS "BBSType" BBSType
foundstatus = 1
if findstring(BBSType, "Auntie") || findstring(BBSType, "RBBS")
getotherprompt(GOTOMAIN)
endif
if findstring(BBSType, "Auntie")
transmit "QMD^M"
else
when quiet 1 call checkmailprompt
holding()
clearwhen quiet
transmit "d^M"
;Wait for a prompt indicated presense of mail
when quiet 1 call checkmail
holding()
clearwhen quiet
if foundstatus == 0
Pending = "0"
ItemC++
strupdt Item Pending 0 1
return
endif
;If there is mail...
transmit "y^M"
endif
;Wait until asked to start the download
profilerd MailRun BBS "MailDLPrompt" MailDLPrompt
profilerd MailRun BBS "CommandPrompt" CommandPrompt
when target 0 MailDLPrompt call endhold
when target 1 CommandPrompt call killmaildl
holding()
clearwhen target 0
clearwhen target 1
;If the command prompt has put in an appearance, abort the d/l
if foundstatus == 0
Pending = "0"
ItemC++
strupdt Item Pending 0 1
return
endif
;Download to the mail download directory
MailDLDir = makefullname(MailRunDir, "MAILDL")
mkdir MailDLDir
cleardir(MailDLDir)
set dnldpath MailDLDir
strfmt temp "%s.QWK" BBS
profilerd MailRun BBS "MailXferProt" MailXferProt
getfile MailXferProt temp
;Hold until the transfer starts
holding()
;Hold until the transfer finishes
waitxfer()
if xferstatus == 2
;If the download was successful...
;Make sure the mail file has the ".QWK" extension.
;This complicated workaround is the only way I could
;figure out how to get the filename of a file that has
;just been downloaded.
temp = makefullname(MailDLDir, "*.*")
findfirst temp
temp = makefullname(MailDLDir, $FILENAME)
MailFile = makefullname(MailDLDir, BBS)
strcat MailFile ".QWK"
rename temp MailFile
;Renumber the QWK packets
renameqwk(MailFile)
;and mark it as completed
Pending = "0"
ItemC++
else
;Otherwise, mark the item as an error
Pending = "2"
ItemE++
capturescreen()
capturestr "`r`n`r`n***** Error in File Transfer *****`r`n`r`n"
endif
;Delete the mail download directory
cleardir(MailDLDir)
chdir MailRunDir
rmdir MailDLDir
strupdt Item Pending 0 1
endproc
#comment
*********************************************************************
*
* CHECKMAIL()
*
* Called by getmail()
*
* Calls findstring(), endhold()
*
* Checks prompt for presense of a mail packet.
*
*********************************************************************
#endcomment
proc checkmail
string ReceiveQWKPrompt, MailPrompt
profilerd MailRun BBS "ReceiveQWKPrompt" ReceiveQWKPrompt
profilerd MailRun BBS "MailPrompt" MailPrompt
if findstring(prompt, MailPrompt)
foundstatus = 0
endhold()
elseif findstring(prompt, ReceiveQWKPrompt)
endhold()
endif
endproc
#comment
*********************************************************************
*
* KILLMAILDL()
*
* Called by getmail()
*
* If there is no mail packet, kills attempt to d/l.
*
*********************************************************************
#endcomment
proc killmaildl
foundstatus = 0
endhold()
endproc
#comment
*********************************************************************
*
* RENAMEQWK()
*
* Called by getmail()
*
* Calls makefullname()
*
* Renames QWK packets after a successful mail download.
*
*********************************************************************
#endcomment
proc renameqwk
strparm MailFile
string OldMail1, OldMail2, MailDir
string char
integer i, j
profilerd MailRun "MailRun" "MailDir" MailDir
OldMail2 = makefullname(MailDir, BBS)
profilerd MailRun "MailRun" "SavePackets" i
;max of 10 packets
if i > 10
i = 10
endif
i -= 1
if i > 0
strfmt OldMail2 "%s.QW%d" OldMail2 i
elseif i == 0
strfmt OldMail2 "%s.QW0" OldMail2
else
strfmt OldMail2 "%s.QWK" OldMail2
endif
;Delete oldest file
delfile OldMail2
OldMail1 = OldMail2
strlen OldMail1 j
j -= 1
while i > 0
i--
itoa i char
strupdt OldMail1 char j 1
;Rename the second oldest as the oldest
rename OldMail1 OldMail2
;Rotate filenames
OldMail2 = OldMail1
endwhile
if i == 0
;if the oldest is QW0...
strupdt OldMail1 "K" j 1
rename OldMail1 OldMail2
OldMail2 = OldMail1
endif
delfile OldMail2
copyfile MailFile OldMail1
delfile MailFile
endproc
#comment
*********************************************************************
*
* ULFILE()
*
* Called by dobbs()
*
* Calls getconfprompt(), getcommandprompt(), getotherprompt(),
* holding(), waitxfer(), checkdescprompt(), findstring(),
* checkverifyprompt(), gotuldlprompt(), senddesc(),
* capturescreen()
*
* Uploads a file to the current BBS.
*
*********************************************************************
#endcomment
proc ulfile
string Pending, ULPrompt, ULDescPrompt, UploadDir, XferProt
string FileName, BBSType
profilerd MailRun BBS "BBSType" BBSType
Pending = "2"
strextract FileName Item "," 3
strextract Conf item "," 4
;Change conferences if necessary
getcommandprompt()
if findstring(BBSType, "PCBoard") || findstring(BBSType, "WildCat")
getconfprompt()
endif
if !(findstring(BBSType, "PCBoard"))
getotherprompt(GOTOFILE)
endif
if findstring(BBSType, "WildCat")
transmit "u^M"
when quiet 1 call checkdescprompt
holding()
clearwhen quiet
else
transmit "u;"
endif
transmit FileName
if findstring(BBSType, "Auntie")
transmit ";n"
endif
transmit "^M"
;Check whether file is already on the board
when quiet 1 call checkdescprompt
holding()
clearwhen quiet
if foundstatus == 1
if !(findstring(BBSType, "RBBS"))
senddesc(FileName)
endif
if findstring(BBSType, "Auntie")
when quiet 1 call checkverifyprompt
holding()
clearwhen quiet
endif
profilerd MailRun BBS "ULPrompt" ULPrompt
when target 0 ULPrompt call gotuldlprompt
when quiet 1 call checkdescprompt
holding()
clearwhen quiet
clearwhen target 0
xferstatus = 1
profilerd MailRun "MailRun" "UploadDir" UploadDir
set upldpath UploadDir
profilerd MailRun BBS "XferProt" XferProt
sendfile XferProt FileName
;Wait until the transfer starts
holding()
;Wait until the transfer finishes
waitxfer()
if xferstatus == 2
;If the download was successful...
if findstring(BBSType, "RBBS")
when quiet 1 call checkverifyprompt
holding()
clearwhen quiet
profilerd MailRun BBS "ULDescPrompt" ULDescPrompt
when target 0 ULDescPrompt call endhold
when quiet 1 call checkdescprompt
holding()
clearwhen quiet
clearwhen target 0
if foundstatus == 1
senddesc(FileName)
when quiet 1 call checkdescprompt
holding()
clearwhen quiet
endif
endif
;Mark as completed
Pending = "0"
ItemC++
else
;Otherwise, mark as an error
ItemE++
capturescreen()
capturestr "`r`n`r`n***** Error in File Transfer *****`r`n`r`n"
endif
else
;If the file was already on the board
;Send a carriage return to get the prompt back
transmit "^M"
if findstring(BBSType, "WildCat")
pause 1
transmit "A^M"
endif
ItemC++
endif
strupdt Item Pending 0 1
endproc
#comment
*********************************************************************
*
* CHECKVERIFYPROMPT()
*
* Called by ulfile()
*
* Calls findstring(), endhold()
*
* Checks for prompt to send the category or file area to
* which a file should be uploaded.
*
*********************************************************************
#endcomment
proc checkverifyprompt
string BBSType
profilerd MailRun BBS "BBSType" BBSType
if findstring(BBSType, "Auntie") && findstring(prompt, "editor function")
transmit "s^M"
elseif findstring(prompt, "category")
transmit Conf
if findstring(BBSType, "Auntie")
transmit ";y;n^M"
endif
endhold()
endif
endproc
#comment
*********************************************************************
*
* SENDDESC()
*
* Called by ulfile()
*
* Calls checkfile(), makefullname(), openfile(), interfaceon(),
* interfaceoff(), findstring()
*
* Sends the file description of a file to be uploaded;
* otherwise sends "Description not available".
*
*********************************************************************
#endcomment
proc senddesc
strparm FileName
string UDXString, UDXFile, MRunUDX, MRunUBF, BBSType
string DB, DL
integer char
long DescBegin, DescLength
long counter
profilerd MailRun BBS "BBSType" BBSType
MRunUDX = makefullname(MailRunDir, "MAILRUN.UDX")
MRunUBF = makefullname(MailRunDir, "MAILRUN.UBF")
;If the file is not on the board, send a description
if checkfile(MRunUDX) && checkfile(MRunUBF)
interfaceoff()
openfile(MRunUBFFile, MRunUBF, _READWRITE, _NORMAL)
openfile(MRunUDXFile, MRunUDX, _READWRITE, _TEXT)
fgets MRunUDXFile UDXString
strextract UDXFile UDXString "`t" 0
while not strcmpi UDXFile FileName
fgets MRunUDXFile UDXString
strextract UDXFile UDXString "`t" 0
endwhile
strextract DB UDXString "`t" 4
strextract DL UDXString "`t" 5
atol DB DescBegin
atol DL DescLength
if findstring(BBSType, "WildCat")
if DescLength > 60
DescLength = 60
endif
endif
if findstring(BBSType, "RBBS")
if DescLength > 45
DescLength = 45
endif
endif
fseek MRunUBFFile DescBegin 0
for counter = 1 upto DescLength
fgetc MRunUBFFile char
computc char
endfor
fclose MRunUBFFile
fclose MRunUDXFile
interfaceon()
else
transmit "Description not available"
endif
transmit "^M"
if findstring(BBSType, "PCBoard") || findstring(BBSType, "Auntie")
transmit "^M"
endif
endproc
#comment
*********************************************************************
*
* DLFILE()
*
* Called by dobbs()
*
* Calls getconfprompt(), getcommandprompt(), getotherprompt(),
* holding(), waitxfer(), putdesc(), findstring(),
* checkdescprompt(), gotuldlprompt(), capturescreen()
*
* Downloads a file from the current BBS.
*
*********************************************************************
#endcomment
proc dlfile
string Pending, DLPrompt, DownloadDir, XferProt, FileName, BBSType
profilerd MailRun BBS "BBSType" BBSType
strextract FileName Item "," 3
strextract Conf Item "," 4
;Change conferences if necessary
getcommandprompt()
if !(findstring(BBSType, "Auntie"))
getconfprompt()
endif
if !(findstring(BBSType, "PCBoard"))
getotherprompt(GOTOFILE)
endif
if findstring(BBSType, "WildCat")
transmit "d^M"
when quiet 1 call checkdescprompt
holding()
clearwhen quiet
else
transmit "d;"
endif
transmit FileName
transmit "^M"
;Check whether file is available for d/l
profilerd MailRun BBS "DLPrompt" DLPrompt
when target 0 DLPrompt call gotuldlprompt
when quiet 1 call checkdescprompt
holding()
clearwhen quiet
clearwhen target 0
if foundstatus == 1
;If it is available...
profilerd MailRun "MailRun" "DownloadDir" DownloadDir
set dnldpath DownloadDir
profilerd MailRun BBS "XferProt" XferProt
getfile XferProt FileName
;Wait until the transfer starts
holding()
;Wait until the transfer finishes
waitxfer()
if xferstatus == 2
;If the download was successful...
putdesc(FileName)
;Mark as completed
Pending = "0"
ItemC++
else
;Otherwise, mark as an error
Pending = "2"
ItemE++
capturescreen()
capturestr "`r`n`r`n*** Error in File Transfer ***`r`n`r`n"
endif
else
;If file was unavailable, mark as error.
Pending = "2"
ItemE++
;Send a return to get the prompt back.
transmit "^M"
endif
strupdt Item Pending 0 1
endproc
#comment
*********************************************************************
*
* PUTDESC()
*
* Called by dlfile()
*
* Calls openfile(), checkfile(), interfaceoff(), interfaceon(),
* makefullname()
*
* Searches the BBSs .IDX file for a file description and
* copies the description from the .DBF file to the uplaod
* files database. If no description is found, a line
* including the file name, size and date is put in the
* upload files index.
*
*********************************************************************
#endcomment
proc putdesc
strparm FileName
string DB, DL, idxString, MRunUDX, MRunUBF, BBSidx, BBSdbf
string idxFile, idxDesc, FileDate, FullFileName, DownloadDir
integer inidx, char
long DescBegin, DescLength, counter, FileSize
interfaceoff()
;Determine whether the BBS index and database files exist
BBSidx = makefullname(MailRunDir, BBS)
strfmt BBSdbf "%s.DBF" BBSidx
strcat BBSidx ".IDX"
inidx = 0
if checkfile(BBSidx) && checkfile(BBSdbf)
;If both files exist...
openfile(BBSidxFile, BBSidx, _READWRITE, _TEXT)
fgets BBSidxFile idxString
while not feof BBSidxFile
;Loop through the index file and stop if the file is found
strextract idxFile idxString "`t" 0
if strcmpi FileName idxFile
inidx = 1
exitwhile
endif
fgets BBSidxFile idxString
endwhile
fclose BBSidxFile
endif
strlwr FileName
;Get the file size and date
profilerd MailRun "MailRun" "DownloadDir" DownloadDir
FullFileName = makefullname(DownloadDir, FileName)
getfsize FullFileName FileSize
getfdate FullFileName FileDate
;Determine whether the upload index and database files exist
MRunUDX = makefullname(MailRunDir, "MAILRUN.UDX")
MRunUBF = makefullname(MailRunDir, "MAILRUN.UBF")
if checkfile(MRunUBF) && checkfile(MRunUDX)
;If both files exist, open them
openfile(MRunUBFFile, MRunUBF, _READWRITE, _NORMAL)
openfile(MRunUDXFile, MRunUDX, _READWRITE, _NORMAL)
else
;Otherwise, create them
openfile(MRunUBFFile, MRunUBF, _CREATE, _NORMAL)
openfile(MRunUDXFile, MRunUDX, _CREATE, _NORMAL)
endif
fseek MRunUDXFile 0 2
if inidx == 1
;If the file was found in the BBS index...
strextract idxDesc idxString "`t" 3
;Get the descriptions starting point and length...
strextract DB idxString "`t" 4
strextract DL idxString "`t" 5
atol DB DescBegin
atol DL DescLength
openfile(BBSdbfFile, BBSdbf, _READWRITE, _NORMAL)
fseek BBSdbfFile DescBegin 0
fseek MRunUBFFile 0 2
ftell MRunUBFFile DescBegin
;And copy each character of the description to the upload database
for counter = 1 upto DescLength
fgetc BBSdbfFile char
fputc MRunUBFFile char
endfor
fclose BBSdbfFile
;Format the upload index entry
fstrfmt MRunUDXFile "%s`t%ld`t%s`t%s`t%ld`t%ld`r`n" \
FileName FileSize FileDate idxDesc DescBegin DescLength
else
;If there was no entry in the BBS index...
;Format the upload index entry
fstrfmt MRunUDXFile "%s`t%ld`t%s`t`t0`t0`r`n" FileName FileSize FileDate
endif
fclose MRunUBFFile
fclose MRunUDXFile
interfaceon()
endproc
#comment
*********************************************************************
*
* SENDCOMMAND()
*
* Called by dobbs()
*
* Calls getcommandprompt(), getotherprompt(), holding(),
* findstring()
*
* Sends commands to the current BBS. A command item may
* contain multiple command lines separated by a vertical
* bar. The script will send these one at a time, waiting
* until the terminal has been quiet for 15 seconds before
* sending the next one. The command must return the user
* to the Main Command Prompt, or be the last item for the
* BBS.
*
*********************************************************************
#endcomment
proc sendcommand
string CommandLine, Command, BBSType
integer j
getcommandprompt()
profilerd MailRun BBS "BBSType" BBSType
if !(findstring(BBSType, "PCBoard"))
getotherprompt(GOTOMAIN)
endif
strextract Command Item "," 3
j = 0
strextract CommandLine Command "|" j
while not NULLSTR CommandLine
if j != 0
when quiet 10 call endhold
holding()
clearwhen quiet
endif
transmit CommandLine
transmit "^M"
j++
strextract CommandLine Command "|" j
endwhile
strupdt Item "0" 0 1
endproc
#comment
*********************************************************************
*
* SENDSCRIPT()
*
* Called by dobbs()
*
* Calls getcommandprompt(), getotherprompt(), mailrunbox(),
* findstring(), makefullname()
*
* Executes a script file. The script must return to the
* Main Command Prompt, or be the last item for that BBS.
*
*********************************************************************
#endcomment
proc sendscript
string ScriptName, BBSType
getcommandprompt()
profilerd MailRun BBS "BBSType" BBSType
if !(findstring(BBSType, "PCBoard"))
getotherprompt(GOTOMAIN)
endif
strextract ScriptName Item "," 3
ScriptName = makefullname(MailRunDir, ScriptName)
execute ScriptName
strupdt Item "0" 0 1
mailrunbox()
endproc
#comment
*********************************************************************
*
* LOGOFF()
*
* Called by dobbs()
*
* Logs off the current BBS.
*
*********************************************************************
#endcomment
proc logoff
integer i = 1
if $CARRIER
transmit "g^M"
endif
pause 5
while $CARRIER && (i < 3)
hangup
pause 5
i++
endwhile
endproc
#comment
*********************************************************************
*
* MAILRUNBOX()
*
* Called by main(), sendscript()
*
* Draws the main MailRun dialog box.
*
*********************************************************************
#endcomment
proc mailrunbox
destroydlg
MainBoxTabs = "20,30,220,230,233,236,239,242"
HelpPage = 2
dialogbox 8 36 346 181 15 "MailRun" HELPID HelpPage
groupbox 10 33 228 135 "Task List" shadow
flistbox 15 52 218 102 TaskList MainBoxTabs single TaskItem
text 15 153 49 8 left "# = permanent"
text 76 153 49 8 left "ñ = temporary"
text 140 153 33 8 left "! = error"
text 182 153 53 8 left "@ = completed"
groupbox 244 33 90 135 "Statistics" shadow
text 248 55 62 8 right "BBSs in mailrun:"
text 248 69 62 8 right "BBSs completed:"
text 248 83 62 8 right "BBSs left to call:"
text 248 97 62 8 right "Items in mailrun:"
text 248 111 62 8 right "Items completed:"
text 248 125 62 8 right "Item errors:"
text 248 139 62 8 right "Items remaining:"
text 248 153 62 8 right "Dialing Attempt:"
vtext 314 55 16 9 left BBSTotal
vtext 314 69 16 9 left BBSComplete
vtext 314 83 16 9 left BBSRemaining
vtext 314 97 16 9 left ItemTotal
vtext 314 111 16 9 left ItemComplete
vtext 314 125 16 9 left ItemError
vtext 314 139 16 9 left ItemRemaining
vtext 314 153 16 9 left AttemptNum
text 102 14 74 8 right "The current mailrun is:"
combobox 180 12 76 41 MailRunTrunc MailRunTrunc
pushbutton 0 0 0 0 " &t" normal default
pushbutton 0 0 0 0 " &u" normal
pushbutton 0 0 0 0 " &i" normal
enddialog
disable CTRL 170
endproc
#comment
*********************************************************************
*
* CAPTURESCREEN()
*
* Called by main(), holding(), sendmail(), getmail(),
* ulfile(), dlfile()
*
* Puts the current screen in the capture file. Normally, the
* contents of a terminal screen are not placed in the capture
* file until they scroll off. If a capture string is placed in
* a capture file, it will appear before the last screenfull of
* data. This procedure is necessary to ensure that a capture
* string appears after all data that has already been received
* from the remote.
*
*********************************************************************
#endcomment
proc capturescreen
string RowString
integer Row, MaxRows, MaxCols
fetch terminal rows MaxRows
fetch terminal columns MaxCols
for Row = 0 upto MaxRows
termgets Row 0 RowString MaxCols
capturestr RowString
capturestr "`r`n"
endfor
termreset
endproc